var thinkjs = require('thinkjs');
var path = require('path');

require('babel-polyfill');

var colors = require('colors/safe');
colors.enabled = true;

var rootPath = path.dirname(__dirname);
var VIEW_PATH = rootPath + '/view';


// 清理编译目录
var fs = require('fs-promise');
fs.removeSync(rootPath + '/www/static/build/');

// antd 开启 style 后，node 端运行需另起进程
var child_process = require('child_process');
var c = child_process.exec('npm run webpack -- --watch --colors');
c.stdout.pipe(process.stdout);
c.stderr.pipe(process.stdout);

require("babel-core/register")({
	only: VIEW_PATH,
});

var instance = new thinkjs({
	APP_PATH: rootPath + path.sep + 'app',
	RUNTIME_PATH: rootPath + path.sep + 'runtime',
	ROOT_PATH: rootPath,
	RESOURCE_PATH: __dirname,
	env: 'development'
});

//compile src/ to app/
instance.compile({
	log: true,
	presets: [],
	plugins: []
});


// 监听view变化
var viewReloadInstance = instance.getReloadInstance(VIEW_PATH);
viewReloadInstance.run();

instance.run();